package life.system.product.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import life.system.product.entity.SortEntity;
import life.system.product.service.SortService;
import life.system.common.utils.PageUtils;
import life.system.common.utils.R;



@RestController
@RequestMapping("product/sort")
public class SortController {
    @Autowired
    private SortService sortService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = sortService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		SortEntity psmSort = sortService.getById(id);

        return R.ok().put("psmSort", psmSort);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody SortEntity psmSort){
		sortService.save(psmSort);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody SortEntity psmSort){
		sortService.updateById(psmSort);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		sortService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }


    /**
     * 获取全部数据
     */
    @RequestMapping("/getAll")
    public R getAll(){
        List<SortEntity> list = sortService.list();
        return R.ok().put("data",list);
    }
}
